<?php
/**
 *
 * @author Taimur khan
 */
class WebsiteSetting extends AppModel {
/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'setting';

  /**
   * The cache key used to cache the settings with
   *
   * @var string
   */
  protected $_cacheKey = 'website_settings';
  /**
   * Clears cache files after saving
   *
   */

  public function afterSave($created, $options = array()) {
    parent::afterSave($created, $options = array());
    Cache::delete($this->_cacheKey);
  }


  /**
   * Returns the an array of setting => value pairs. Handles caching.
   *
   * @return array
   */
  public function getSettings() {
    if ($websiteSettings = Cache::read($this->_cacheKey)) {
      return $websiteSettings;
    }
    $websiteSettings = $this->find('list', array(
      'fields' => array('setting', 'value',)
    ));
    Cache::write($this->_cacheKey, $websiteSettings);
    return $websiteSettings;
  }

}
